#!encoding:utf-8
from lxml import etree
import os
import urllib
import codecs


import sys







def enparse(url,path,xpath_string):
        print url +'********************'
	page=unicode(urllib.urlopen(url,'utf-8').read(),'utf-8')
	selector = etree.HTML(page)
	selector = selector.xpath(xpath_string)
	if xpath_string.endswith('text()'):
	    for x in selector:
	         print x
	         f=codecs.open(path,'w','utf-8')
	         f.write('\n'.join(selector))
	else:
	    for xx in [x.xpath('string(.)') for x in selector]:
	        print xx
	        f=codecs.open(path,'w','utf-8')
                print path
	        f.write('\n'.join([x.xpath('string(.)') for x in selector]))
with open('1.txt')as f:
	lines=f.readlines()

for x in lines:
    filename=x.split('/')[-1].split('.')[0]
    enparse('http://www.kekenet.com/'+x,'FILE/'+filename,"//div[@class=\"qh_en\"]/p")

